import { Module } from 'vuex'
import { ReviewState, RootState } from '../types'
import { ReviewService } from '@/api/review'

const reviewModule: Module<ReviewState, RootState> = {
  namespaced: true,
  
  state: {
    loading: false
  },
  
  mutations: {
    SET_LOADING(state, loading: boolean) {
      state.loading = loading
    }
  },
  
  actions: {
    async submitReviews({ commit }, reviews) {
      commit('SET_LOADING', true)
      try {
        const response = await ReviewService.submitReviews(reviews)
        return response.data
      } finally {
        commit('SET_LOADING', false)
      }
    },
    
    async getProductReviews({ commit }, productId) {
      const response = await ReviewService.getProductReviews(productId)
      return response.data
    }
  }
}

export default reviewModule 